package com.eboss2.sbs.activity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.eboss2.sbs.R;
import com.eboss2.sbs.activity.base.BaseActivity;
import com.eboss2.sbs.config.Config;
import com.eboss2.sbs.http.HttpUtil;
import com.eboss2.sbs.model.PointBalanceInfo;
import com.eboss2.sbs.myapplication.MyApplication;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.loopj.android.http.RequestParams;
import com.mytools.tool.activityManager.MyActivityManager;
import com.tool.utils.utils.StringUtils;
import com.tool.utils.utils.ToastUtils;
import com.tool.utils.view.ShapeView;

import org.json.JSONObject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MyPointBlanceActivity extends BaseActivity {


    private static final String TAG = "MyPointBlanceActivity";
    @BindView(R.id.titleback_btn_back)
    LinearLayout titlebackBtnBack;

    @BindView(R.id.tv_amt)
    TextView tvAmt;
    @BindView(R.id.monthMulPoint)
    TextView monthMulPoint;
    @BindView(R.id.totalMulPoint)
    TextView totalMulPoint;
    @BindView(R.id.rl_hx)
    RelativeLayout rlHx;
    @BindView(R.id.rl_gz)
    RelativeLayout rlGz;
    @BindView(R.id.id_status)
    ShapeView idStatus;
    private TextView tv_amt;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = this;
        setContentView(R.layout.activity_mypoint);
        ButterKnife.bind(this);
        MyActivityManager.getInstance().addActivity(this);
        initView();
    }

    private void initView() {
        RelativeLayout relativeLayout = relativeLayout(R.id.lv_heard);
        relativeLayout.setBackgroundColor(getResources().getColor(R.color.statusBar));
        showView(R.id.titleback_btn_back, true);
        setTvText(R.id.tv_title, "积分余额");
        showView(R.id.next_sure, false);
        getdata();
    }


    private void getdata() {

        showProgress("加载中...");
        RequestParams params = new RequestParams();

        params.put("shopId", MyApplication.getmInstance().getLoginMEntity().getShopid() + "");
        HttpUtil.get(Config.SBS_BONUSINFO, params, new HttpUtil.RequestListener() {
            @Override
            public void success(String response) {
                disShowProgress();
                try {
                    JSONObject result = new JSONObject(response);

                    if (!result.optBoolean("status")) {
                        ToastUtils.CustomShow(mContext, result.optString("message"));
                    } else {
                        PointBalanceInfo pointBalanceInfo = new Gson().fromJson(result.optString("data"), new TypeToken<PointBalanceInfo>() {
                        }.getType());
                        if (pointBalanceInfo != null) {
                            tvAmt.setText(StringUtils.addComma(pointBalanceInfo.getBonusNumber() + ""));
                            monthMulPoint.setText(pointBalanceInfo.getMonthVeriftyBonus() + "");
                            totalMulPoint.setText(pointBalanceInfo.getTotalVeriftyBonus() + "");
                            idStatus.setText(pointBalanceInfo.getStatus());
                        }
                    }
                } catch (Exception e) {
                    Log.e(TAG, "doLogin() Exception: " + e.getMessage());
                }


            }

            @Override
            public void failed(Throwable error) {
                disShowProgress();
                showE404();
            }
        });
    }


    @OnClick({R.id.titleback_btn_back, R.id.rl_hx, R.id.rl_gz})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.titleback_btn_back:
                finish();
                break;
            case R.id.rl_hx:
                startActivity(new Intent(mContext, PointVerificationReportActivity.class));
                break;
            case R.id.rl_gz:
                startActivity(new Intent(mContext, MyPointRuleActivity.class));
                break;
        }
    }
}
